import requests
import execjs

# 读取并编译 JavaScript 文件
with open('CodeJsDemo01.js', 'r', encoding='utf-8') as file:
    script_code = file.read()

# 执行 JavaScript 代码并获取结果
ctx = execjs.compile(script_code)
v = ctx.call('res')

# print(v)

cookies = {
    'cid': '7eee3fc023932ceca9ea2aac30ddce9a1724331523',
    'other_uid': 'Ths_iwencai_Xuangu_ynt61dfcpswcq8wq2xahbi8qdvo8erp0',
    'ta_random_userid': 'd399ggu21i',
    'v': v,
}

headers = {
    'Accept': 'application/json, text/plain, */*',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Cache-control': 'no-cache',
    'Connection': 'keep-alive',
    'Content-Type': 'application/json',
    # 'Cookie': 'cid=7eee3fc023932ceca9ea2aac30ddce9a1724331523; other_uid=Ths_iwencai_Xuangu_ynt61dfcpswcq8wq2xahbi8qdvo8erp0; ta_random_userid=d399ggu21i; v=A7LhOF1CABPkXzwupDVQqQxpA_ORQ7S-6EeqAXyJ3mVQD1ytZNMG7bjX-gJP',
    'Origin': 'https://www.iwencai.com',
    'Pragma': 'no-cache',
    'Referer': 'https://www.iwencai.com/unifiedwap/result?w=5g&querytype=stock&addSign=1725892814142',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0',
    'hexin-v': 'A7LhOF1CABPkXzwupDVQqQxpA_ORQ7S-6EeqAXyJ3mVQD1ytZNMG7bjX-gJP',
    'sec-ch-ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Microsoft Edge";v="122"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}

json_data = {
    'source': 'Ths_iwencai_Xuangu',
    'version': '2.0',
    'query_area': '',
    'block_list': '',
    'add_info': '{"urp":{"scene":1,"company":1,"business":1},"contentType":"json","searchInfo":true}',
    'question': '5g',
    'perpage': 50,
    'page': 1,
    'secondary_intent': 'stock',
    'log_info': '{"input_type":"typewrite"}',
    'rsh': 'Ths_iwencai_Xuangu_ynt61dfcpswcq8wq2xahbi8qdvo8erp0',
}

response = requests.post(
    'https://www.iwencai.com/customized/chart/get-robot-data',
    cookies=cookies,
    headers=headers,
    json=json_data,
).text
print(response)